package huawei.js2025;

/**
 * 双十一 最大花费金额
 */
public class Question7 {

    public int getMaxCost(int[] prices, int totalAmount) {
        int maxCost = 0;

        for (int i = 0; i < prices.length - 2; i++) {
            for (int j = i + 1; j < prices.length - 1; j++) {
                for (int k = j + 1; k < prices.length; k++) {
                    int sum = prices[i] + prices[j] + prices[k];
                    if (sum <= totalAmount) {
                        maxCost= Math.max(maxCost, sum);
                    }
                }
            }
        }

        return maxCost;
    }

    public static void main(String[] args) {
        int[] prices = {23,26,36,27};

        Question7 question7 = new Question7();
        int maxCost = question7.getMaxCost(prices, 77);
        System.out.println(maxCost);
    }
}
